package com.sitech.portal.system.dao.ibatis;

import java.util.HashMap;
import java.util.List;

import com.sitech.ibnms.core.BaseIbnmsDao;
import com.sitech.ibnms.core.IPage;
import com.sitech.ibnms.core.PageForm;
import com.sitech.portal.system.dao.ISysPanelConfigDao;

public class SysPanelConfigDaoImpl extends BaseIbnmsDao implements ISysPanelConfigDao {

	public HashMap findObjTB_SYS_PANEL_CONFIGByPanelID(String PANEL_ID) {
			return (HashMap) this.querySingle(
					"findObjTB_SYS_PANEL_CONFIGByPanelID", PANEL_ID);
	}

	public List findSysPanelConfigList() {
			return this.query("findSysPanelConfigList", null);
	}

	public List findSysPanelConfigListByRole(String portalRole) {
			String sql = "select * from TB_SYS_PANEL_CONFIG where panel_id in("
					+ portalRole + ")" + "order by PANEL_ID ";
			return this
					.query("findSysPanelConfigListByRole", sql);
	}

	// 获得个人待处理任务列表
	public List loadTodoTaskList(String login_id) {
		String mySql = "";
		mySql = "SELECT   distinct a.*,  c.cactivityname, d.uppertime ,c.CVIEWJSP,e.PROC_NAME "
				+ " FROM (select aa.CSHEETTYPE,cc.NAME,a.ITASKID,a.ICURRACTID,a.ISERIALNO,a.IENTITYID,a.IPREACTID,a.ISTAFFID,a.IGRANTORID,a.ITASKSTATUS,a.IACTIVITYTYPE,a.DDATECREATED,a.DDATEACCEPTED,a.DDATEALLOW,a.CTITLE,a.IPRETASKID,a.EXEC_DBRULE,a.ISTAFFWG,a.IPROCESSID,a.IDEAL_TYPE,aa.ICURRDEALER "
				+ " from to_do_task_list a, TO_DO_TASK_STATUS aa,TB_SYS_LOGINMSG cc "
				+ " where a.ISERIALNO = aa.ISERIALNO"
				+ " and a.ITASKID = aa.ITASKID "
				+ " and aa.ICURRDEALER = cc.LOGIN_ID(+) ";
		mySql += "and a.IPROCESSID in (select PROC_ID from PROCESS )";

		mySql += " ) a, activity c,TO_DO_TASK_STATUS d,PROCESS e"
				+ " WHERE a.icurractid = c.iactivityid"
				+ " and a.itaskid=d.itaskid " + " and e.PROC_ID=c.IPROCESSID";

		mySql += " AND (a.istaffid = '"
				+ login_id
				+ "' or a.ICURRDEALER='"
				+ login_id
				+ "')"
				+ " AND a.iactivitytype = '2' and (ideal_type != '1' or ideal_type is null) "
				+ " and a.ITASKID not in (select ITASKID from TO_DO_TASK_ENGINE) ";

		mySql += "  ORDER BY ddatecreated DESC";
		return this.query("loadTodoTaskList", mySql);
	}

	public void add(HashMap map) {
			this.insert("insertForTbSYS_PANEL_CONFIG", map);
	}

	public void update(HashMap map) {
			this.update("updateForTbSYS_PANEL_CONFIG", map);
	}

	public void deleteByPKs(String pId) {

			this.delete("deleteForTbSYS_PANEL_CONFIGByPKS", pId);
	}

	public IPage findListByPK(PageForm pageForm) {
			String mySql = "";
			mySql = "  select PANEL_ID,PANEL_NAME,PANEL_PATH,PANEL_HEIGHT "
					+ " from TB_SYS_PANEL_CONFIG  where 1=1";
			mySql += " ORDER BY PANEL_ID ";
			return this.findPage(
					"findListForTB_SYS_PANEL_CONFIGByPK", mySql,pageForm);
	}

	public HashMap findObjByPK(String pId) {
			return (HashMap) this.querySingle(
					"findObjForTB_SYS_PANEL_CONFIGByPK", pId);
	}
}
